package com.yunhai.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.device.service.FdsBusinessStartRulesetService;
import com.yunhai.model.entity.fds.FdsBusinessStartRulesetEntity;
import com.yunhai.model.vo.fds.FdsBusinessStartRulesetQuery;
import com.yunhai.model.vo.fds.FdsBusinessStartRulesetVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/fdsBusinessStartRuleset")
public class FdsBusinessStartRulesetController {

	@Resource
	private FdsBusinessStartRulesetService fdsBusinessStartRulesetService;


	/**
	 * 获取 FdsBusinessStartRuleset 分页列表
	 */
	@GetMapping("/pagination")
	public Ret getFdsBusinessStartRulesetPagination(PaginationVo paginationVo, FdsBusinessStartRulesetQuery fdsBusinessStartRulesetQuery ) throws Exception {
		IPage page = fdsBusinessStartRulesetService.getFdsBusinessStartRulesetPagination(paginationVo, fdsBusinessStartRulesetQuery );
		return Ret.toPage(page);
	}


	/**
	 * 获取 FdsBusinessStartRuleset 所有数据
	 */
	@GetMapping("/allList")
	public Ret getFdsBusinessStartRulesetAllList( FdsBusinessStartRulesetQuery fdsBusinessStartRulesetQuery ) throws Exception {
		List<FdsBusinessStartRulesetEntity> list = fdsBusinessStartRulesetService.getFdsBusinessStartRulesetAllList( fdsBusinessStartRulesetQuery );
		return Ret.ok(list);
	}


	/**
	 * 获取 FdsBusinessStartRuleset 详情
	 */
	@GetMapping("/{id}")
	public Ret getFdsBusinessStartRulesetDetailById(@PathVariable Long id) throws Exception {

	    FdsBusinessStartRulesetEntity fdsBusinessStartRulesetEntity = fdsBusinessStartRulesetService.getFdsBusinessStartRulesetDetail(id);
		return Ret.ok(fdsBusinessStartRulesetEntity);
	}


	/**
	 * 新增 FdsBusinessStartRuleset
	 * */
	@PostMapping("")
	public Ret addFdsBusinessStartRuleset(@RequestBody FdsBusinessStartRulesetVo fdsBusinessStartRulesetVo) throws Exception {

		fdsBusinessStartRulesetVo.setEnabled(1);
		fdsBusinessStartRulesetService.addFdsBusinessStartRuleset(fdsBusinessStartRulesetVo);
		return Ret.ok();
	}


	/**
	 * 更新 FdsBusinessStartRuleset
	 * */
	@PutMapping("")
	public Ret updateFdsBusinessStartRuleset(@RequestBody FdsBusinessStartRulesetVo fdsBusinessStartRulesetVo) throws Exception {

		fdsBusinessStartRulesetService.updateFdsBusinessStartRuleset(fdsBusinessStartRulesetVo);
		return Ret.ok();
	}


	/**
	 * 删除 FdsBusinessStartRuleset
	 * */
	@PostMapping("/batchRemove")
	public Ret batchRemoveFdsBusinessStartRuleset( @RequestBody List<Long> ids ) throws Exception {

	    fdsBusinessStartRulesetService.batchRemoveFdsBusinessStartRuleset(ids);
		return Ret.ok();
	}
}
